﻿using LPLS.Commons.DBModule;
using LPLS.DBEntities;
using LPLS.DBEntities.DataCollectionModels;
using LPLS.DBInterface.DataCollectionModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LPLS.DBServices.DataCollectionModels
{
    public class DataCollectionRecordService : DBBaseService, IDataCollectionRecordService
    {
        public DataCollectionRecordService(DBContext dbContext) : base(dbContext)
        {
        }

        public int AddData(DataCollectionRecord record)
        {
          return this.Client.Insertable<DataCollectionRecord>(record).ExecuteCommand();
        }

        public List<DataCollectionRecord> GetData()
        {
            return this.Client.Queryable<DataCollectionRecord>().ToList();
        }

        public List<DataCollectionRecord> GetData(Guid Deviceid, Guid compentid)
        {
             return this.Client.Queryable<DataCollectionRecord>().Where(e=>e.DeviceId==Deviceid&&e.CompentId==compentid).ToList();
        }

        public List<DataCollectionRecord> GetData(Guid deviceID)
        {
            return this.Client.Queryable<DataCollectionRecord>().Where(e=>e.DeviceId==deviceID).ToList();
        }

        public List<DataCollectionRecord> GetData(int take)
        {
            return this.Client.Queryable<DataCollectionRecord>().Take(take).Where(e=>e.IsCollection==0).ToList();
        }

        public override void InitDataBaseName()
        {
            DataBaseName = DatabaseEnum.CollectionConfigDB.ToString();
        }

        public int UpdateData(DataCollectionRecord record)
        {
           return this.Client.Updateable<DataCollectionRecord>(record).ExecuteCommand();
        }

        public int UpdateData(List<int> ids)
        {
         return  this.Client.Updateable<DataCollectionRecord>()
                            .SetColumns(it => new DataCollectionRecord() { IsCollection =1 })//类只能在表达示里面不能提取
                            .Where(it => ids.Contains(it.Id))
                            .ExecuteCommand();
        }
    }
}
